package com.book.controller.api;

import com.book.service.AuthService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @Author zzw2000
 * @Date 2022年08月25日 11:28
 * @Description 描述
 */
@Controller
@RequestMapping("/api/auth")
public class AuthApiController {
    @Resource
    private AuthService authService;

    @PostMapping("/register")
    public String register(@RequestParam("username") String username,
                           @RequestParam("password") String password,
                           @RequestParam("sex") String sex,
                           @RequestParam("grade") int grade) {
        boolean flag = authService.register(username, password, sex, grade);
        if (flag)
            return "redirect:/login";
        return "redirect:/register";
    }
}
